package com.itheima.controller;


import com.itheima.domain.User;
import com.itheima.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpRequest;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

@Controller
@RequestMapping("user")
public class UserController {

    @Autowired
    private UserService userService;

    @RequestMapping("login")
    public String login(User user, HttpSession session, HttpServletRequest request){
        User userFind = userService.findByNameAndPassword(user);
        if(userFind!=null){
            //证明验证成功,存储user 跳转页面
            session.setAttribute("user",userFind);
            return "redirect:/student/findAll";
        }else {
            //证明用户名或密码错误
            request.setAttribute("msg","用户名或密码错误");
            return "login";
        }
    }
}
